//Documentation complete
/**
 * @author Kazu
 * @version 2009MR23
 */

package ui.internal;

import control.*;
import problemDomain.*;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.*;

/**
 * Servlet implementation class ReportProfitabilityPopularity
 */
public class ReportSalesTimePeriod extends HttpServlet {
	
	/* Constants */
	
	private static final long serialVersionUID = 8879893224320238911L;
	
	/* END Constants */
	
	
	/* (HttpServlet) Methods */
	
	@Override
	protected void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String from = request.getParameter("dateFrom");
		String to = request.getParameter("dateTo");
		String periodStr = request.getParameter("timePeriod");
		
		if (from != null && to != null && periodStr != null) {
			PrintWriter out = response.getWriter();
			try {
				
				SalesTimePeriodReportControl stprc = new SalesTimePeriodReportControl();
				SalesPerTimePeriodReportBean report = stprc.report(from, to, periodStr);
				
				out.write(report.toXML());
			} catch (ErrorBean e) {
				out.write(e.toXML());
			} finally {
				out.close();
			}
		}
	}
	
	/* (HttpServlet) Methods */
	
}
